package com.dlc.shop.allinpay.service;

import com.dlc.shop.allinpay.config.AllinpayConfig;
import com.dlc.shop.common.allinpay.order.req.*;
import com.dlc.shop.common.allinpay.order.resp.*;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Component;

/**
 * 订单服务 测试
 *
 * @author LGH
 */
@Component
@AllArgsConstructor
public class AllinpayOrderService {

    private final AllinpayConfig allinpayConfig;

    /**
     * 冻结金额
     *
     * @param fm 冻结参数
     * @return FreezeMoneyRep 冻结金额返回参数
     */
    public FreezeMoneyResp freezeMoney(FreezeMoney fm) {
        return allinpayConfig.sendData(fm, FreezeMoneyResp.class);
    }

    /**
     * 解冻金额
     *
     * @param um 解冻参数
     * @return FreezeMoneyRep 解冻金额返回参数
     */
    public FreezeMoneyResp unfreezeMoney(UnfreezeMoney um) {
        return allinpayConfig.sendData(um, FreezeMoneyResp.class);
    }


    /**
     * 平台转账
     *
     * @param at 平台转账参数
     * @return applicationTransferReq 平台转账返回参数
     */
    public ApplicationTransferResp applicationTransfer(ApplicationTransfer at) {
        return allinpayConfig.sendData(at, ApplicationTransferResp.class);
    }

    /**
     * 查询余额
     *
     * @param qb 余额参数
     * @return queryBalancereq 查询余额返回参数
     */
    public QueryBalanceResp queryBalance(QueryBalance qb) {
        return allinpayConfig.sendData(qb, QueryBalanceResp.class);
    }

    /**
     * 查询订单状态
     */
    public OrderDetailResp orderDetail(GetOrderDetail od) {
        return allinpayConfig.sendData(od, OrderDetailResp.class);
    }

    /**
     * 查询账户收支明细
     */
    public QueryInExpDetailResp queryInExpDetail(QueryInExpDetail qied) {
        return allinpayConfig.sendData(qied, QueryInExpDetailResp.class);
    }

    /**
     * 单笔托管代付
     *
     * @param agentPay 单笔托管代付
     * @return applicationTransferReq 平台转账返回参数
     */
    public AgentPayResp signalAgentPay(AgentPay agentPay) {
        return allinpayConfig.sendData(agentPay, AgentPayResp.class);
    }

    /**
     * 批量托管代付
     *
     * @param agentPay 批量托管代付
     * @return applicationTransferReq 平台转账返回参数
     */
    public BatchAgentPayResp batchAgentPay(BatchAgentPay agentPay) {
        return allinpayConfig.sendData(agentPay, BatchAgentPayResp.class);
    }

    /**
     * 退款申请
     *
     * @param refund 单笔托管代付
     * @return applicationTransferReq 平台转账返回参数
     */
    public RefundResp doRefund(Refund refund) {
        return allinpayConfig.sendData(refund, RefundResp.class);
    }

    /**
     * 托管代收申请（标准版）
     *
     * @param ac 托管代收参数
     * @return applicationTransferReq 托管代收返回参数
     */
    public ApplicationCollectionResp agentCollectApply(ApplicationCollection ac) {
        return allinpayConfig.sendData(ac, ApplicationCollectionResp.class);
    }

    /**
     * 确认支付(前台+支付密码)
     *
     * @param payByPwd 余额支付参数
     * @return applicationTransferReq 余额支付返回参数
     */
    public String payByPwd(PayByPwd payByPwd) {
        return allinpayConfig.sendUrlData(payByPwd);
    }

    /**
     * 提现申请
     *
     * @param withdrawApplyReq
     * @return
     */
    public WithdrawApplyResp withdrawApply(WithdrawApplyReq withdrawApplyReq) {
        return allinpayConfig.sendData(withdrawApplyReq, WithdrawApplyResp.class);
    }

    /**
     * 确认支付(前台+短信验证码)
     *
     * @param payBySms
     * @return
     */
    public String payBySms(PayBySms payBySms) {
        return allinpayConfig.sendUrlData(payBySms);
    }

    /**
     * 确认支付 后台+短信验证码
     *
     * @param payByBackSmsReq
     * @return
     */
    public PayByBackSmsResp payByBackSms(PayByBackSmsReq payByBackSmsReq) {
        return allinpayConfig.sendData(payByBackSmsReq, PayByBackSmsResp.class);
    }

    /**
     * 重发支付短信验证码
     *
     * @param resendPaySmsReq
     * @return
     */
    public ResendPaySmsResp resendPaySms(ResendPaySmsReq resendPaySmsReq) {
        //2. 验证码发送规则：验证码在有效期内，发原验证码，过有效期，发新的验证码；
        //3. 验证码发送频次：10s内不允许重复调用该接口，避免暴力发送短信验证码，返回错误信息“调用重发短信接口太频繁，请稍后再试！”；
        //4. 若订单状态为支付完成、进行中、支付失败、关闭；超过订单过期时间（上送取过期时间值判断、未上送取30分钟判断），返回错误信息“订单处理完成或处理中，不支持重发短信！”；
        return allinpayConfig.sendData(resendPaySmsReq, ResendPaySmsResp.class);
    }

    /**
     * 充值申请
     *
     * @param depositApply
     * @return
     */
    public DepositApplyResp depositApply(DepositApply depositApply) {
        return allinpayConfig.sendData(depositApply, DepositApplyResp.class);
    }

    /**
     * 消费申请
     *
     * @param consumeApply
     * @return
     */
    public ConsumeApplyResp consumeApply(ConsumeApply consumeApply) {
        return allinpayConfig.sendData(consumeApply, ConsumeApplyResp.class);
    }

    /**
     * 订单支付状态查询
     *
     * @param getOrderStatus
     * @return
     */
    public OrderStatusResp getOrderStatus(GetOrderStatus getOrderStatus) {
        return allinpayConfig.sendData(getOrderStatus, OrderStatusResp.class);
    }

    /**
     * 获取订单信息
     *
     * @param getOrderStatusReq
     * @return
     */
    public GetOrderStatusResp getOrderStatus(GetOrderStatusReq getOrderStatusReq) {
        return allinpayConfig.sendData(getOrderStatusReq, GetOrderStatusResp.class);
    }

	/**
	 * 平台头寸查询
	 * @param queryReserveFundBalanceReq
	 * @return
	 */
	public QueryReserveFundBalanceResp queryReserveFundBalance(QueryReserveFundBalanceReq queryReserveFundBalanceReq) {
		return allinpayConfig.sendData(queryReserveFundBalanceReq, QueryReserveFundBalanceResp.class);
	}
}
